#include /* * CapitiveSense Library Demo Sketch * Paul Badger 2008 * Uses a high value resistor e.g. 10M between send pin and receive pin * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values. * Receive pin is the sensor pin - try different amounts of foil/metal on this pin */ CapacitiveSensor cs_4_1 = CapacitiveSensor(2,3); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired CapacitiveSensor cs_4_2 = CapacitiveSensor(2,4); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil CapacitiveSensor cs_4_3 = CapacitiveSensor(2,5); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil CapacitiveSensor cs_4_4 = CapacitiveSensor(2,6); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired CapacitiveSensor cs_4_5 = CapacitiveSensor(2,7); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil CapacitiveSensor cs_4_6 = CapacitiveSensor(2,8); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil void setup() { cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example Serial.begin(9600); pinMode(9, OUTPUT); pinMode(14, OUTPUT); pinMode(15, OUTPUT); pinMode(16, OUTPUT); pinMode(22, OUTPUT); pinMode(23, OUTPUT); } void loop() { long start = millis(); long total1 = cs_4_1.capacitiveSensor(30); long total2 = cs_4_2.capacitiveSensor(30); long total3 = cs_4_3.capacitiveSensor(30); long total4 = cs_4_4.capacitiveSensor(30); long total5 = cs_4_5.capacitiveSensor(30); long total6 = cs_4_6.capacitiveSensor(30); if (total1>3000) { digitalWrite(9, HIGH); } else { digitalWrite(9, LOW); } if (total2>3000) { digitalWrite(14, HIGH); } else { digitalWrite(14, LOW); } if (total3>3000) { digitalWrite(15, HIGH); } else { digitalWrite(15, LOW); } if (total4>3000) { digitalWrite(16, HIGH); } else { digitalWrite(16, LOW); } if (total5>3000) { digitalWrite(22, HIGH); } else { digitalWrite(22, LOW); } if (total6>3000) { digitalWrite(23, HIGH); } else { digitalWrite(23, LOW); } Serial.print(millis() - start); // check on performance in milliseconds Serial.print("\t"); // tab character for debug windown spacing Serial.print(total1); // print sensor output 1 Serial.print("\t"); Serial.print(total2); // print sensor output 2 Serial.print("\t"); Serial.println(total3); // print sensor output 3 Serial.print("\t"); Serial.print(total4); // print sensor output 1 Serial.print("\t"); Serial.print(total5); // print sensor output 2 Serial.print("\t"); Serial.println(total6); // print sensor output 3 Serial.print("\t"); delay(10); // arbitrary delay to limit data to serial port }